// pages/menu/menu.js
// 高度累加的一个数组 默认第一项为0
let heightArr = [0]
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // 左侧当前项
    leftNum:0,
    // 右侧当前值的id
    rightId:'right0',
    indicatordots:false,
    autoplay:true,
    interval:2000,
    current: 0,
    index:0,
    backgroundArr: [
      "/images/banner/baner1.jpg",
      "/images/banner/baner2.jpg",
      "/images/banner/baner3.jpg",
      "/images/banner/baner4.jpg"
    ],
      "arr": [
        {
          "id": 0,
          "title": "人气Top",
          "subArr": [
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "拿铁" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "桃桃芝士红宝石" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "咖啡风味安慕希" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "陨石拿铁" }
          ]
        },
        {
          "id": 1,
          "title": "大师咖啡",
          "subArr": [
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "冲绳黑糖拿铁" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "陨石拿铁" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "拿铁" }
          ]
        },
        {
          "id": 2,
          "title": "小鹿茶精选",
          "subArr": [
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "标准美式" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "加浓美式" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "焦糖标准美式" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "焦糖加浓拿铁" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "银河气泡美式" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "银河气泡美式" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "银河气泡美式" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "银河气泡美式" }
          ]
        },
        {
          "id": 3,
          "title": "瑞纳冰",
          "subArr": [
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "乐岛桃桃冰" }
          ]
        },
        {
          "id": 4,
          "title": "鲜榨果蔬汁",
          "subArr": [
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "NFC鲜榨橙汁" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "NFC鲜榨西柚汁" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "猕猴桃复合果汁" }
          ]
        },
        {
          "id": 5,
          "title": "经典饮品",
          "subArr": [
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "巧克力" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "纯牛奶" }
          ]
        },
        {
          "id": 6,
          "title": "健康轻食",
          "subArr": [
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "京味烤鸭鲜蔬卷" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "夏威夷菠萝火山卷" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "火腿芝士羊角" },
            { "imgSrc": "/images/menu/1-1.jpg", "imgDesc": "鸡肉卷" }
          ]
        }
      ],
    // testArr:['cc','bb','aa']
  },
  // 子传父
  // fatherEventFn(data){
  //   console.log(data.detail)
  // },

  onReady(){
   setTimeout(() => {
    const query = wx.createSelectorQuery()
    query.selectAll('.box').boundingClientRect()
    query.selectViewport().scrollOffset()
    query.exec((res)=>{
    
      res[0].map(item =>{
        let result = heightArr[heightArr.length-1]+ item.height
        heightArr.push(result)
      })
      console.log(heightArr);
      // res[0].top       // #the-id节点的上边界坐标
    // res[1].scrollTop // 显示区域的竖直滚动位置
   }, 500);
})
  },
    // 右侧滚动
    scollFn(event){
      let st = event.detail.scrollTop
      // console.log(st);
      for(var i = 0;i < heightArr.length;i++){
        if(st>=heightArr[i]&&st<heightArr[i+1]-50){
            this.setData({
              leftNum:i
            })
            return
        }
      }
    },
 natie(e){
    // console.log(e);
    this.setData({
      current:e.detail.current
    })
  },
  // 左侧的点击事件
  leftClick(e){
    // 拿到索引值
    // console.log(e);
    // 先去自定义一个索引值  拿到索引值
    let index = e.currentTarget.dataset.myindex
    this.setData({
      leftNum:index,
      rightId:'right'+index
    })
    // console.log(leftNum)
  },
  // 右侧和左侧菜单 右侧滑动会带着左侧一起动
  
})